////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   COMPANY
// AUTHOR           :   Victor Zheng 
// DATE CREATE      :   2006/02/01
// DESCRIPTION      :   a MAINTENANCE FORM file for the function, COMPANY
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2006/02/01   Victor Zheng    1.0                 source is generated.
//
//
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.app.admin.companySetup.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.erp.framework.controller.form.SimpleMaintStyleForm;
import com.erp.framework.util.logger.Logger;

import com.erp.app.common.ProjectConstants;
import com.erp.app.common.util.ProjectCommonUtil;
import com.erp.app.util.web.ActionErrorUtil;
import com.erp.framework.util.CommonUtil;
import com.erp.framework.model.schema.TableSchema;

import com.erp.app.admin.errorMsg.pk.ErrorMsgLabelPk;
import com.erp.app.admin.errorMsg.vo.ErrorMsgLabelVo;

import java.util.HashMap;

/**
* <p>A <strong>MaintenanceForm</strong> is a JavaBean which provides property
* getter and setter methods for all of the bean properties, and implements
* <code>Serializable</code>, as required by the JavaBean specification
* The main purpose for this bean is to get the user input
* from the web browsers.
*
* @author          Victor Zheng 
* @version 1.0     2006/02/01
* @since           FrameWork 1.0
*
*/
public class CompanyMaintenanceForm extends SimpleMaintStyleForm {

	//Header Attributes (DB Table Name: T_COMPANY)
	private String companyCode;                      //DB Column Name: COMPANY_CODE
	private String shortName;                        //DB Column Name: SHORT_NAME
	private String longName;                         //DB Column Name: LONG_NAME
	private String addr1;                            //DB Column Name: ADDR1
	private String addr2;                            //DB Column Name: ADDR2
	private String addr3;                            //DB Column Name: ADDR3
	private String country;                          //DB Column Name: COUNTRY
	private String phone;                            //DB Column Name: PHONE
	private String fax;                              //DB Column Name: FAX
	private String ccy;                              //DB Column Name: CCY
	private String baseCcy;                          //DB Column Name: BASE_CCY
	private String contentType;                      //DB Column Name: CONTENT_TYPE
	private byte[] companyLogo;                        //DB Column Name: COMPANY_LOGO
	private String createUser;                       //DB Column Name: CREATE_USER
	private String createDate;                       //DB Column Name: CREATE_DATE
	private String updateUser;                       //DB Column Name: UPDATE_USER
	private String updateDate;                       //DB Column Name: UPDATE_DATE
	private String addr4;                            //DB Column Name: ADDR4
	private String ledgerCode;                       //DB Column Name: LEDGER_CODE
	private String postalCode;                       //DB Column Name: POSTAL_CODE
	private String privacyCode;                      //DB Column Name: PRIVACY_CODE
	private String printFormFont;                    //DB Column Name: PRINT_FORM_FONT
	private String phoneArea;
	private String phoneCountry;
	private String faxArea;
	private String faxCountry;

	/**
	* Validate the properties that have been set for this non-HTTP request,
	* and return an <code>ActionErrors</code> object that encapsulates any
	* validation errors that have been found.  If no errors are found, return
	* <code>null</code> or an <code>ActionErrors</code> object with no
	* recorded error messages.
	* <p>
	* The default implementation attempts to forward to the HTTP version of
	* this method.
	*
	* @param      the action errors array
	* @author     Victor Zheng 
	* @since      FrameWork 1.0
	*/
	public void otherValidate(ActionErrors errors) {

		validateCompany(errors);
	}

	/**
	* Validate the properties that have been set for this non-HTTP request,
	* and return an <code>ActionErrors</code> object that encapsulates any
	* validation errors that have been found.  If no errors are found, return
	* <code>null</code> or an <code>ActionErrors</code> object with no
	* recorded error messages.
	* <p>
	* The default implementation attempts to forward to the HTTP version of
	* this method.
	*
	* @param      errors The errors array that is used for storing validation errors
	* @author     Victor Zheng 
	* @since      FrameWork 1.0
	*/
	public void validateCompany(ActionErrors errors) {

        TableSchema ts = getTs();
        String validateFeildName = new String();
        String errMessge = new String();

        HashMap errMsgMap = getErrMsgMap();
        ErrorMsgLabelPk pk = null;

        validateFeildName = ts.getDisplayWebLabelWithColonByObjectId("LBL_COMPANY_COMPANY_CODE");
        if (CommonUtil.isEmpty(companyCode)){
   			ActionErrorUtil.addErrorForGeneralFieldBlank(errors, validateFeildName);
        }

        validateFeildName = ts.getDisplayWebLabelWithColonByObjectId("LBL_COMPANY_SHORT_NAME");
        if (CommonUtil.isEmpty(shortName)){
   			ActionErrorUtil.addErrorForGeneralFieldBlank(errors, validateFeildName);
        }

        validateFeildName = ts.getDisplayWebLabelWithColonByObjectId("LBL_COMPANY_LONG_NAME");
        if (CommonUtil.isEmpty(longName)){
   			ActionErrorUtil.addErrorForGeneralFieldBlank(errors, validateFeildName);
        }

        validateFeildName = ts.getDisplayWebLabelWithColonByObjectId("LBL_COMPANY_LEDGER_CODE");
        if (CommonUtil.isEmpty(ledgerCode)){
   			ActionErrorUtil.addErrorForGeneralFieldBlank(errors, validateFeildName);
        }

        validateFeildName = ts.getDisplayWebLabelWithColonByObjectId("LBL_COMPANY_ADDR1");
        if (CommonUtil.isEmpty(addr1)){
   			ActionErrorUtil.addErrorForGeneralFieldBlank(errors, validateFeildName);
        }
        
        validateFeildName = ts.getDisplayWebLabelWithColonByObjectId("LBL_COMPANY_COUNTRY");
        if (CommonUtil.isEmpty(country)){
   			ActionErrorUtil.addErrorForGeneralFieldBlank(errors, validateFeildName);
        }

        validateFeildName = ts.getDisplayWebLabelWithColonByObjectId("LBL_COMPANY_PHONE");
        if (CommonUtil.isEmpty(phone)){
   			ActionErrorUtil.addErrorForGeneralFieldBlank(errors, validateFeildName);
        }else if (phone.length() > 20){
            //
            pk = new ErrorMsgLabelPk(getCompanyCode(), 
                                         DBMENU_GENERAL_MENU, 
                                         ProjectConstants.MOD_COMPANY_SETUP, 
                                         ProjectConstants.MOD_COMPANY_SETUP_OUT_OF_LENGTH_TEL, 
                                         getSysLangCode());
            errMessge = ((ErrorMsgLabelVo)errMsgMap.get(pk)).getObjectWebLabel();
            ActionErrorUtil.addErrorForSpecficPurpose(errors , errMessge);
        }
        

        validateFeildName = ts.getDisplayWebLabelWithColonByObjectId("LBL_COMPANY_FAX");
        if (CommonUtil.isEmpty(fax)){
   			ActionErrorUtil.addErrorForGeneralFieldBlank(errors, validateFeildName);
        } else if (fax.length() >20){
            //
            pk = new ErrorMsgLabelPk(getCompanyCode(), 
                                         DBMENU_GENERAL_MENU, 
                                         ProjectConstants.MOD_COMPANY_SETUP, 
                                         ProjectConstants.MOD_COMPANY_SETUP_OUT_OF_LENGTH_FAX, 
                                         getSysLangCode());
            errMessge = ((ErrorMsgLabelVo)errMsgMap.get(pk)).getObjectWebLabel();
            ActionErrorUtil.addErrorForSpecficPurpose(errors , errMessge);
        }
        

        validateFeildName = ts.getDisplayWebLabelWithColonByObjectId("LBL_COMPANY_CCY");
        if (CommonUtil.isEmpty(ccy)){
   			ActionErrorUtil.addErrorForGeneralFieldBlank(errors, validateFeildName);
        }

        validateFeildName = ts.getDisplayWebLabelWithColonByObjectId("LBL_COMPANY_BASE_CCY");
        if (CommonUtil.isEmpty(baseCcy)){
   			ActionErrorUtil.addErrorForGeneralFieldBlank(errors, validateFeildName);
        }

		/*
		TableSchema ts = getTs();
		ArrayList companyRowList = getMultiRows(CompanyMaintenanceAction.TAB_IDX_COMPANY);

		for (int i = 0; (companyRowList != null) && (i < companyRowList.size()); i++) {
			CompanyRow row = (CompanyRow) companyRowList.get(i);

		}
		*/
		
	}

	/**
	* Validate the properties that have been set for this non-HTTP request,
	* and return an <code>ActionErrors</code> object that encapsulates any
	* validation errors that have been found.  If no errors are found, return
	* <code>null</code> or an <code>ActionErrors</code> object with no
	* recorded error messages.
	* <p>
	* The default implementation attempts to forward to the HTTP version of
	* this method.
	*
	* @param      mapping      the action mapping
	* @param      formIn       the action form
	* @param      request      the http request
	* @param      response     the http response
	* @param      errors       the action errors array
	* @author     Victor Zheng 
	* @since      FrameWork 1.0
	*/
	public void moreValidate(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		CompanyMaintenanceForm form = (CompanyMaintenanceForm) formIn;

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	/**
	* Reset all bean properties to their default state.  This method
	* is called inside the reset() method.
	*
	* @param      mapping The mapping used to select this instance
	* @param      request The servlet request we are processing
	* @author     Victor Zheng 
	* @since      FrameWork 1.0
	*/
	public void otherReset(ActionMapping mapping, HttpServletRequest request) {
		
	}

	/**
	* Converts to a string representing the data in this object.
	* A new <code>String</code> object is allocated and initialized to 
	* contain the character sequence currently represented by this 
	* object. This <code>String</code> is then returned. Subsequent 
	* changes to this object do not affect the contents of the 
	* <code>String</code>. 
	*
	* @return     a string representation of the object.
	* @see        java.lang.Object#toString()
	* @author     Victor Zheng 
	* @since      FrameWork 1.0
	*/
	public String toString() {
		String pkStr = "PK: {companyCode = " + this.companyCode + "}\n";
		String colStr = "COL: {shortName = " + this.shortName
			+ "\n, longName = " + this.longName
			+ "\n, addr1 = " + this.addr1
			+ "\n, addr2 = " + this.addr2
			+ "\n, addr3 = " + this.addr3
			+ "\n, country = " + this.country
			+ "\n, phone = " + this.phone
			+ "\n, fax = " + this.fax
			+ "\n, ccy = " + this.ccy
			+ "\n, baseCcy = " + this.baseCcy
			+ "\n, contentType = " + this.contentType
			+ "\n, createUser = " + this.createUser
			+ "\n, createDate = " + this.createDate
			+ "\n, updateUser = " + this.updateUser
			+ "\n, updateDate = " + this.updateDate
			+ "\n, addr4 = " + this.addr4
			+ "\n, ledgerCode = " + this.ledgerCode
			+ "\n, postalCode = " + this.postalCode
			+ "\n, privacyCode = " + this.privacyCode
			+ "\n, printFormFont = " + this.printFormFont + "}\n";
		return "CompanyMaintenanceForm.toString() (header only) is:\n" + pkStr + colStr;
	}

	////////////////////////////////////////////////////////////////////////////////
	//Generated Accessors (get/set methods) for Header (Company)
	////////////////////////////////////////////////////////////////////////////////

	public String getCompanyCode() {
		return this.companyCode;
	}

	public String getShortName() {
		return this.shortName;
	}

	public String getLongName() {
		return this.longName;
	}

	public String getAddr1() {
		return this.addr1;
	}

	public String getAddr2() {
		return this.addr2;
	}

	public String getAddr3() {
		return this.addr3;
	}

	public String getCountry() {
		return this.country;
	}

	public String getPhone() {
		return this.phone;
	}

	public String getFax() {
		return this.fax;
	}

	public String getCcy() {
		return this.ccy;
	}

	public String getBaseCcy() {
		return this.baseCcy;
	}

	public String getContentType() {
		return this.contentType;
	}

	public byte[] getCompanyLogo() {
		return this.companyLogo;
	}

	public String getCreateUser() {
		return this.createUser;
	}

	public String getCreateDate() {
		return this.createDate;
	}

	public String getUpdateUser() {
		return this.updateUser;
	}

	public String getUpdateDate() {
		return this.updateDate;
	}

	public String getAddr4() {
		return this.addr4;
	}

	public String getLedgerCode() {
		return this.ledgerCode;
	}

	public String getPostalCode() {
		return this.postalCode;
	}

	public String getPrivacyCode() {
		return this.privacyCode;
	}

	public String getPrintFormFont() {
		return this.printFormFont;
	}
	
	public String getPhoneArea() { return phoneArea; }
	
	public String getPhoneCountry() { return phoneCountry; }
	
	public String getFaxArea() { return faxArea; }
	
	public String getFaxCountry() { return faxCountry; }

	public void setCompanyCode(String companyCode) {
		this.companyCode = ProjectCommonUtil.toCode(companyCode);
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public void setLongName(String longName) {
		this.longName = longName;
	}

	public void setAddr1(String addr1) {
		this.addr1 = addr1;
	}

	public void setAddr2(String addr2) {
		this.addr2 = addr2;
	}

	public void setAddr3(String addr3) {
		this.addr3 = addr3;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public void setCcy(String ccy) {
		this.ccy = ccy;
	}

	public void setBaseCcy(String baseCcy) {
		this.baseCcy = baseCcy;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public void setCompanyLogo(byte[] companyLogo) {
		this.companyLogo = companyLogo;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}

	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}

	public void setUpdateDate(String updateDate) {
		this.updateDate = updateDate;
	}

	public void setAddr4(String addr4) {
		this.addr4 = addr4;
	}

	public void setLedgerCode(String ledgerCode) {
		this.ledgerCode = ledgerCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public void setPrivacyCode(String privacyCode) {
		this.privacyCode = privacyCode;
	}

	public void setPrintFormFont(String printFormFont) {
		this.printFormFont = printFormFont;
	}
	
	public void setPhoneArea(String phoneArea) { this.phoneArea = phoneArea; }
	
	public void setPhoneCountry(String phoneCountry) { this.phoneCountry = phoneCountry; }
	
	public void setFaxArea(String faxArea) { this.faxArea = faxArea; }
	
	public void setFaxCountry(String faxCountry) { this.faxCountry = faxCountry; }
	
	////////////////////////////////////////////////////////////////////////////////
	//Other Accessors (get/set methods)
	////////////////////////////////////////////////////////////////////////////////


}